package com.enpronomics.pcall.receivers;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.telephony.SmsMessage;

import com.enpronomics.pcall.ServiceManager;
import com.enpronomics.pcall.activity.DeleteSmsActivity;

public class MessageReceiver extends BroadcastReceiver {

	@Override
	public void onReceive(Context context, Intent intent) {
		ServiceManager.alarm = true;
		Bundle bundle = intent.getExtras();
		if (bundle != null) {
			Object[] pdus = (Object[]) bundle.get("pdus");
			SmsMessage sms = SmsMessage.createFromPdu((byte[]) pdus[0]);

			if (sms.getMessageBody().contains(ServiceManager.REMOTE_REQUEST)) {
				Intent myIntent = new Intent(context, DeleteSmsActivity.class);
				myIntent.putExtras(bundle);
				myIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
				context.startActivity(myIntent);
			}
		}
	}
}
